export const getNowDate = () => {
    var timestamp = Date.parse(new Date());
    var date = new Date(timestamp);
    //获取年份  
    var Y = date.getFullYear();
    //获取月份  
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    //获取当日日期 
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    return Y + '年' + M + '月' + D + '日';
}
export const login = () => {
    return new Promise((resolve, reject) => {
        wx.login({
            success: resolve,
            fail: (err) => {
                reject('login方法出问题了' + err)
            },
        });
    })
}
export const getSetting = () => {
    return new Promise((resolve, reject) => {
        wx.getSetting({
            success: resolve,
            fail: () => {
                reject('getSetting方法出问题了')
            },
        });
    })

}
export const showModal = (options) => {
    return new Promise((resolve, reject) => {
        wx.showModal({
            title: '温馨提示',
            ...options,
            success: resolve,
            fail: () => {
                reject('showModal方法出问题了')
            },
        });
    })

}
export const formatDate = (timestamp) => {
    let toDou = n => n < 10 ? `0${n}` : `${n}`;
    let date = new Date(parseInt(timestamp));
    return `${date.getFullYear()}年${toDou(date.getMonth()+1)}月${toDou(date.getDate())}日`;
}
export const dataGroup = (array, key) => {  //对数组中对象某个属性分组
    
    let sortArr = array.sort((a, b) => { //根据数组的 key 排序
        return a.key < b.key ? -1 : 1;
    })
    let groupArr = {};
    sortArr.forEach(obj => {
        let arr = groupArr[obj[key]] || []
        arr.push(obj)
        groupArr[obj[key]] = arr
    });
    return groupArr;
}